<h1>云信 Web SDK Online Test</h1>
<div>
  <p>
    <span>APPKEY:</span>
    <input type="text" id="appkey" value="45c6af3c98409b18a84451215d0bdd6e" />
  </p>
  <p>
    <span>ACCOUNT:</span>
    <input type="text" id="account" value="greatcs4" />
  </p>
  <p>
    <span>TOKEN:</span>
    <input type="text" id="token" value="e10adc3949ba59abbe56e057f20f883e" />
  </p>
  <p>
    <button id="connect-sdk">连接SDK</button>
  </p>
</div>
<script src="http://yx-web.nos.netease.com/official/websdk/NIM_Web_SDK_v4.8.0.js"></script>

<script>
  function connectSDK () {
    var appkey = document.getElementById('appkey').value
    var account = document.getElementById('account').value
    var token = document.getElementById('token').value
    window.nim = SDK.NIM.getInstance({
      appKey: appkey,
      account: account,
      token: token,
      onconnect: function () {
        alert('SDK 连接成功')
        // 连接成功后才能发消息
        window.nim.sendText({
          scene: 'p2p',
          to: 'account',
          text: 'hello',
          done: function sendMsgDone (msg) {}
        })
      },
      ondisconnect: function (obj) {
        console.log('SDK 连接断开', obj)
      },
      onerror: function (error) {
        console.log('SDK 连接失败', error)
      }
    })
  }

  document.getElementById('connect-sdk').addEventListener('click', function () {
    connectSDK()
  })
</script>
